package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "频道管理API借口", tags = "频道管理API接口")
@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController {
    @Autowired
    private AdChannelService channelService;

    @ApiOperation(value = "根据频道名称分页查询频道列表", notes = "详细描述")
    @PostMapping("/list")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return channelService.findByNameAndPage(dto);
    }

    @ApiOperation(value = "保存频道", notes = "详细描述")
    @PostMapping("/save")
    public ResponseResult save(@RequestBody AdChannel channel) {
        return channelService.insert(channel);
    }

    @ApiOperation(value = "更新频道", notes = "描述个锤子，不懂更新建议回家继承家产")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody AdChannel channel) {

        return channelService.update(channel);
    }

    @GetMapping("/channels")
    public ResponseResult findAll() {
        return this.channelService.findeAll();
    }


    @GetMapping("/del/{id}")
    @ApiOperation(value = "删除频道", notes = "删除就是点一下就爆炸的键没错吧233")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {

        return channelService.delete(id);
    }

}
